package com.ysqcould.web.controller.allocation;


import com.ysqcould.allocation.domain.Contacts;
import com.ysqcould.allocation.service.IContactsService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.revita.domain.GslNotice;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.apache.http.util.ByteArrayBuffer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

/**
 * 通信录Controller
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/allocation/contacts")
public class ContactsController extends BaseController
{
    @Autowired
    private IContactsService contactsService;

    /**
     * 查询通信录列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:contacts:list')")
    @GetMapping("/list")
    public TableDataInfo list(Contacts contacts)
    {
        startPage();
        List<Contacts> list = contactsService.selectContactsList(contacts);
        return getDataTable(list);
    }

    /**
     * 导出通信录列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:contacts:export')")
    @Log(title = "通信录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Contacts contacts)
    {
        List<Contacts> list = contactsService.selectContactsList(contacts);
        ExcelUtil<Contacts> util = new ExcelUtil<Contacts>(Contacts.class);
        util.exportExcel(response, list, "通信录数据");
    }

    /**
     * 获取通信录详细信息
     */
    @PreAuthorize("@ss.hasPermi('allocation:contacts:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(contactsService.selectContactsById(id));
    }

    /**
     * 新增通信录
     */
    @PreAuthorize("@ss.hasPermi('allocation:contacts:add')")
    @Log(title = "通信录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Contacts contacts)
    {
        contacts.setAsId(getUserId());
        return toAjax(contactsService.insertContacts(contacts));
    }

    /**
     * 修改通信录
     */
    @PreAuthorize("@ss.hasPermi('allocation:contacts:edit')")
    @Log(title = "通信录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Contacts contacts)
    {
        return toAjax(contactsService.updateContacts(contacts));
    }

    /**
     * 删除通信录
     */
    @PreAuthorize("@ss.hasPermi('allocation:contacts:remove')")
    @Log(title = "通信录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(contactsService.deleteContactsByIds(ids));
    }

    /**
     * 状态修改
     */
    @Log(title = "通信录", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody Contacts contacts)
    {
        return toAjax(contactsService.updateStatus(contacts));
    }


    public static void main(String[] args) {

    }
}
